﻿using System.ComponentModel;
using K9Nano.Application.Setting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.AspNetCore.Controllers;

/// <summary>
/// 设置项接口
/// </summary>
[Route("admin/api/setting")]
public class SettingController(ISettingAppService service) : ApiControllerBase
{
    /// <summary>
    /// 修改应用设置
    /// </summary>
    /// <returns></returns>
    [HttpPost("application")]
    [Description("修改应用设置")]
    public async Task ChangeApplicationSetting(SettingChangeInput input)
    {
        await service.ChangeSettingAsync(input, HttpContext.RequestAborted);
    }

    /// <summary>
    /// 获取设置分组
    /// </summary>
    /// <returns></returns>
    [HttpGet("groups")]
    [Description("获取设置分组")]
    public IEnumerable<string> GetGroupsForEdit() => service.GetGroupsForEdit();

    /// <summary>
    /// 获取分组的设置项
    /// </summary>
    /// <param name="name">分组名称</param>
    /// <returns></returns>
    [HttpGet("group/{name}")]
    [Description("获取分组的设置项")]
    public async Task<SettingEditModelGroup?> GetGroupForEditAsync(string name)
         => await service.GetGroupForEditAsync(name, HttpContext.RequestAborted);

    /// <summary>
    /// 修改分组设置项
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("group")]
    [Description("修改分组设置项")]
    public async Task ChangeSettingsAsync(SettingEditModelGroupInput input)
        => await service.ChangeSettingsAsync(input, HttpContext.RequestAborted);

}